<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of OrderDetailDetailDAO
 *
 * @author Beverley
 */
class OrderDetailDAO {
    //put your code here
    public function getOrderDetail($order_id,$product_id) {
        $orderDetail = new OrderDetail();
        $row = $orderDetail->fetchRow("order_id = $order_id and product_id = $product_id and status =".Constant::$STATUS_AVAILABLE);
        return $row;
    }

     public function getOrderDetailListByID($order_id) {
       $order = new OrderDetail();
       $row = $order->fetchAll("order_id = $order_id and status =".Constant::$STATUS_AVAILABLE);
       return $row;
    }

    public function getOrderDetailList() {
        $OrderDetail = new OrderDetail();
        $row = $OrderDetail->fetchAll($OrderDetail->select()->where('status = ?',Constant::$STATUS_AVAILABLE));
        return $row;
    }

    public function addOrderDetail($array) {
        $OrderDetail = new OrderDetail();
        $OrderDetail->insert($array);
    }

    public function editOrderDetail($array) {
        $OrderDetail = new OrderDetail();
        $where1 = $OrderDetail->getAdapter()->quoteInto("order_id = ?",$array['order_id']);
        $where2 = $OrderDetail->getAdapter()->quoteInto("product_id = ?",$array['product_id']);
        $OrderDetail->update($array,array($where1,$where2));
    }

    public function deleteOrderDetail($order_id,$product_id) {
        $OrderDetail = new OrderDetail();
        $data = array("status"=>Constant::$STATUS_DELETED);
        $where1 = $OrderDetail->getAdapter()->quoteInto("order_id = ?",$order_id);
        $where2 = $OrderDetail->getAdapter()->quoteInto("product_id = ?",$product_id);
        $OrderDetail->update($data,array($where1,$where2));
    }

    public function checkCartIsEmpty($array) {
        if (!isset($array)) {
            return true;
        } else {
            foreach($array as $id=>$quantity) {
                if ($quantity > 0)
                    return false;
            }
            return true;
        }
    }
}
?>
